package com.medic.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.medic.entity.Pharmacist;
import com.medic.entity.Weichat;

import com.medic.mapper.interf.PharmacistMapper;
import com.medic.service.interf.PharmacistServiceInterface;
import com.medic.util.CacheUtil;


@Service("pharmacistService")
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)// 注明需要回滚
public class PharmacistServiceImpl implements PharmacistServiceInterface {



	@Resource
	private PharmacistMapper pharmacistMapper;
	

	
	@Resource
	private WeichatServiceImpl weichatService;
	
	
	@Override
	public boolean delete(Pharmacist object) throws Exception {
		pharmacistMapper.delete(object);
		return true;
	}

	@Override
	public boolean save(Pharmacist pat) throws Exception {
				
		pharmacistMapper.save(pat);
		
		Weichat wechat = new Weichat();
		wechat.setOpenid(pat.getOpenid());
		wechat.setRole("pharmacist");
		wechat.setRolename(pat.getName());
		wechat.setRoleid(pat.getId());
		
		
		weichatService.save(wechat);
		
		return true;
	}

	@Override
	public boolean update(Pharmacist object) throws Exception {
		pharmacistMapper.update(object);
		return true;
	}
	
	
	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED)
	public Page<Pharmacist> getPharmacist(int pageno, String where)
			throws Exception {
		PageHelper.startPage(pageno, CacheUtil.getRole_pagesize() );
		
		Page<Pharmacist> page = (Page<Pharmacist>)pharmacistMapper.selectPharmacist(where); 
		
		return page;
	}
	
	
	@Transactional(propagation=Propagation.NOT_SUPPORTED)
	@Override
	public Pharmacist getPharmacist(int pharmacistid) throws Exception {
		
		return pharmacistMapper.selectPharmacistByID(pharmacistid);
	}

	
	
}
